# 1. 代码复用

# a = 10
# name = 'zhangsan'
# # print(name+':'+str(a))
#
# b=12
# c=13
# d=15
#
# # print(a+b+c+d)
# l = [a,b,c,d]  # for
# l2 = [3,4,5,6]


# 闭包,  接近类
def func():
    num = 0
    count = 0

    def c(ll):
        nonlocal count
        nonlocal num
        for i in ll:
            count += i
            num += 1

    def show():
        nonlocal count
        nonlocal num
        print(count)
        print(num)

    return c, show


class func1():  # 主类
    # 数据, 方法
    num = 0
    count = 0

    def c(self, ll):
        for i in ll:
            self.count += i
            self.num += 1

    def show(self):
        print(self.count)
        print(self.num)


class func2():  # 混入类
    def avg(self):
        print(self.count / self.num)


class func3(func2, func1):
    pass

# f = func3()
#
# f.c([1,2,3,4])
# f.c([2,3,4,5])
# f.show()
# f.avg()